// function queryString(obj1) {
//     var str = ''
//     for (var key in obj1) {
//         str += key + '=' + obj1[key] + '&'
//     }
//     str = str.slice(0, str.length - 1)
//     return str
// }

$('form').on('submit',e=>{
    e.preventDefault();
     
    let info={
        username: $('.username').val(),
        password: $('.pass').val(),
        rpassword: $('.rpass').val(),
        nickname: $('.nic').val(),

    }
    // console.log(info);
   if(!info.username||!info.password||!info.rpassword||!info.nickname)return alert('请输入完整表格内容')
   if(info.password!==info.rpassword)return alert('两次密码输入不一致')
   $.ajax({
    url: 'http://localhost:8888/users/register',
    method: 'post',                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
    data: info,
    // dataType: 'json',
    success: function (res) {                 
        console.log(res);

        // 如果注册不成功 让error盒子显示
        if (res.code !== 1) {
          $('.show-1').removeClass('show-show')
            return
        }

        // 代码能执行到说明注册成功 跳转到登录页面
        window.location.href = './login.html'

    }
})
})